package com.swu.education.util;

import java.io.File;
import java.io.FileInputStream;

/**
 * Created by nana on 2018/3/24.
 */
public class TxtRead {

  public String readTxt(int activityId,int id){

    String txtName = "File\\"+activityId+"_"+id+".txt";
    File file = new File(txtName);
    if(file.exists()){
      Long fileLengthLong = file.length();
      byte[] fileContent = new byte[fileLengthLong.intValue()];
      try {
        FileInputStream inputStream = new FileInputStream(file);
        inputStream.read(fileContent);
        inputStream.close();
      } catch (Exception e) {
        // TODO: handle exception
      }
      String string = new String(fileContent);
      return string;
    }else {
      return "您的学生还没有开始对话";
    }
  }

  public String deleteTxt(int activityId,int userId){
    String txtName = "File\\"+activityId+"_"+userId+".txt";
    File file = new File(txtName);
    if(file.exists()){
      file.delete();
      return "删除成功";
    }
    else {
      return "文件已经被删除了，不需要再次删除";
    }
  }
}
